#include "DownloadFileRequestCmd.h"

DownloadFileRequestCmd::DownloadFileRequestCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::CloudProtocol;
    this->m_functionCode = FunctionCode;
    this->m_fileType = 0;
}

Package DownloadFileRequestCmd::toPackage()
{
    Package package;
    QByteArray body;

    body.append(DataTypeConver::intToByteArray(m_fileType,1));

    QString param;
    foreach (const QString &key, m_paramMap.keys())
    {
        param += key + "=" + m_paramMap.value(key) + "\n";
    }

    quint16 strLength = param.length();
    body.append(DataTypeConver::intToByteArray(strLength,2));
    body.append(param);

    body = encrypt(body,KeyType::AES);

    package.setId(m_cmdId);
    package.setFunction(FunctionCode);
    package.setBody(body);

    return package;
}

void DownloadFileRequestCmd::unPackage(Package package)
{
    m_cmdId = package.id();
}
quint8 DownloadFileRequestCmd::fileType() const
{
    return m_fileType;
}

void DownloadFileRequestCmd::setFileType(const quint8 &fileType)
{
    m_fileType = fileType;
}
QMap<QString, QString> DownloadFileRequestCmd::paramMap() const
{
    return m_paramMap;
}

void DownloadFileRequestCmd::setParamMap(const QMap<QString, QString> &paramMap)
{
    m_paramMap = paramMap;
}


